/* -*-c++-*- */
/* osgEarth - Dynamic map generation toolkit for OpenSceneGraph
 * Copyright 2008-2013 Pelican Mapping
 * http://osgearth.org
 *
 * osgEarth is free software; you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>
 */
#ifndef OSGEARTH_DRIVER_BING_OPTIONS
#define OSGEARTH_DRIVER_BING_OPTIONS 1

#include <VBF_3DMap/VBF_Terrain/Common.h>
#include <VBF_3DMap/VBF_Terrain/VBF_SourceTile.h>
#include <VBF_3DMap/VBF_Terrain/URI.h>

namespace osgEarth { namespace Drivers 
{
    using namespace osgEarth;

    /**
     * Configuration structure for the Microsoft Bing driver.
     * http://www.bing.com/developers/
     *
     * Using Bing requires an API key. You can get one from the URL above.
     * You are responsible for complying with the Bing terms of service.
     */
    class BingOptions : public CVBF_OptionsDriverSourceTile // NO EXPORT; header only
    {
    public:

        /**
         * API Key to use to access Bing REST services. Required!
         */
        CVBF_Optional<std::string>& key() { return _apiKey; }
        const CVBF_Optional<std::string>& key() const { return _apiKey; }

        /**
         * Imagery set to access. Default is "Aerial".
         *
         * As of this writing, options are:
         *    Aerial
         *    AerialWithImagery
         *    Road
         *
         * (The "Birdseye" layers don't work with this driver at this time.)
         *
         * See (http://msdn.microsoft.com/en-us/library/ff701716.aspx) for more information.
         */
        CVBF_Optional<std::string>& imagerySet() { return _imagerySet; }
        const CVBF_Optional<std::string>& imagerySet() const { return _imagerySet; }

        /**
         * Base URL for the Bing REST API. By default this will point to the
         * Internet Bing services.
         */
        CVBF_Optional<std::string>& imageryMetadataAPI() { return _imageryMetadataAPI; }
        const CVBF_Optional<std::string>& imageryMetadataAPI() const { return _imageryMetadataAPI; }

		CVBF_Optional<URI>& url() { return _url; }
        const CVBF_Optional<URI>& url() const { return _url; }

    public:
        /**
         * Constructs a Bing configuration structure.
         */
        BingOptions( const CVBF_OptionsDriverSourceTile& opt =CVBF_OptionsDriverSourceTile() ) : CVBF_OptionsDriverSourceTile( opt ),
            _imagerySet        ( "Aerial" ),
            _imageryMetadataAPI( "http://dev.virtualearth.net/REST/v1/Imagery/Metadata" )
        {
            setDriver( "bing" );
            fromConfig( m_conf );
        }

        /** dtor */
        virtual ~BingOptions() { }

    public:
        CVBF_Config getConfig() const 
		{
            CVBF_Config conf = CVBF_OptionsDriverSourceTile::getConfig();
			conf.updateIfSet("url",					 _url);
            conf.updateIfSet("key",                  _apiKey);
            conf.updateIfSet("imagery_set",          _imagerySet );
            conf.updateIfSet("imagery_metadata_api", _imageryMetadataAPI );
            return conf;
        }

    protected:
        void mergeConfig( const CVBF_Config& conf ) 
		{
            CVBF_OptionsDriverSourceTile::mergeConfig( conf );
            fromConfig( conf );
        }

    private:
        void fromConfig( const CVBF_Config& conf ) 
		{
			conf.getIfSet("url",					_url);
            conf.getIfSet("key",					_apiKey);
            conf.getIfSet("imagery_set",			_imagerySet );
            conf.getIfSet("imagery_metadata_api",	_imageryMetadataAPI );
        }

		CVBF_Optional<URI>         _url;
        CVBF_Optional<std::string> _apiKey;
        CVBF_Optional<std::string> _imagerySet;
        CVBF_Optional<std::string> _imageryMetadataAPI;
    };

} } // namespace osgEarth::Drivers

#endif // OSGEARTH_DRIVER_BING_OPTIONS
